home *** CD-ROM | disk | FTP | other *** search
- # include "FLMapInfo.h"
- # include "FLMaca.h"
- # include "FaceLift.h"
-
-
- static void
- CSpecToCStr (Boolean mark, ConvSpec *cSpec, ConvStr *cStr, StringPtr defStr)
- {
- MarkToStr (mark, cStr->markStr);
- FontToStr (cSpec->font, cStr->fontStr, defStr);
- SizeToStr (cSpec->size, cStr->sizeStr, defStr);
- StyleToStr (cSpec->style, cStr->styleStr, defStr);
- }
-
-
- void
- ClearCSpec (ConvSpec *cSpec)
- {
- cSpec->font = anyFont;
- cSpec->size = anySize;
- cSpec->style = anyStyle;
- }
-
-
- void
- ClearMSpec (MapSpec *mSpec)
- {
- ClearCSpec (&mSpec->inFmt);
- ClearCSpec (&mSpec->outFmt);
- mSpec->isInput = true;
- }
-
-
- /*
- * Compare two conversion specifications.
- * Return:
- * 0 c1 = c2
- * < 0 c1 < c2
- * > 0 c1 > c2
- *
- * Font sorts before size, which sorts before style.
- *
- * For all of font, size and style, the "any" selection is greater,
- * so that generic selections sort to the end of the list. Font
- * comparisons are otherwise based on the name of the font, rather
- * than its number. A string compare is avoided by keeping the
- * fonts in alphabetic order in the font information structures.
- *
- * Note that the style comparison does not use the manifest constants
- * defined for each style value, and so would break if style coding
- * changed!
- */
-
- short
- CompareCSpec (ConvSpec *c1, ConvSpec *c2)
- {
- int i;
- int s1, s2;
-
- if (c1->font != c2->font)
- {
- if (c1->font == anyFont)
- return (1);
- if (c2->font == anyFont)
- return (-1);
- return (FontIndex (c1->font) - FontIndex (c2->font));
- }
-
- if ((i = c1->size - c2->size) != 0)
- {
- if (c1->size == anySize)
- return (1);
- if (c2->size == anySize)
- return (-1);
- return (i);
- }
-
- s1 = c1->style;
- s2 = c2->style;
- if (s1 - s2 != 0)
- {
- if (s1 == anyStyle)
- return (1);
- if (s2 == anyStyle)
- return (-1);
- for (i = 0; i < 7; ++i)
- {
- if (s1 == 0)
- {
- if (s2 != 0)
- return (-1);
- }
- else if (s2 == 0)
- {
- return (1);
- }
- else if (s1 & 1)
- {
- if (!(s2 & 1))
- return (-1);
- }
- else if (s2 & 1)
- return (1);
- s1 >>= 1;
- s2 >>= 1;
- }
- }
- return (0); /* equal */
- }
-
-
- /*
- * Convert map specs to map text. Do this by converting input specs
- * and output specs.
- */
-
- void
- MSpecToMStr (MapSpec *mSpec, MapStr *mStr)
- {
- CSpecToCStr (mSpec->isInput, &mSpec->inFmt, &mStr->inStr, "\pAny");
- CSpecToCStr (!mSpec->isInput, &mSpec->outFmt, &mStr->outStr, "\pSame");
- }
-
-
- /*
- * Set the mark field with a bullet if the value is true.
- */
-
- void
- MarkToStr (Boolean value, StringPtr str)
- {
- CopyString (value ? "\p\245" : "\p", str);
- }
-
-
- /*
- * The font *must* be legal
- */
-
- void
- FontToStr (int font, StringPtr str, StringPtr defStr)
- {
- if (font == anyFont) /* Any/Same */
- CopyString (defStr, str);
- else
- FontName (FontIndex (font), str);
- }
-
-
- void
- SizeToStr (int size, StringPtr str, StringPtr defStr)
- {
- if (size == anySize) /* no size specified, use default */
- CopyString (defStr, str);
- else
- NumToString ((long) size, str);
- }
-
-
- /*
- * Convert style value to string. If the style has only one attribute
- * bit set, use the attribute name, otherwise use abbreviated form with
- * one letter for each attribute.
- */
-
- static StringPtr styleStr[7] =
- {
- (StringPtr) "\pBold",
- (StringPtr) "\pItalic",
- (StringPtr) "\pUnder",
- (StringPtr) "\pOutline",
- (StringPtr) "\pShadow",
- (StringPtr) "\pHigh",
- (StringPtr) "\pLow"
- };
-
-
- void
- StyleToStr (int style, StringPtr str, StringPtr defStr)
- {
- int i, style2;
-
- if (style == anyStyle) /* no style specified, use default */
- CopyString (defStr, str);
- else if (style == 0) /* no bits set = plain text */
- CopyString ("\pPlain", str);
- else
- {
- style2 = style;
- for (i = 0; i < 7; ++i)
- {
- if ((style2 & 1))
- {
- if (style2 != 1)
- break; /* more than 1 bit set */
- CopyString (styleStr[i], str);
- return;
- }
- style2 >>= 1;
- }
- i = 0;
- if (style & styleBold)
- str[++i] = 'B';
- if (style & styleItalic)
- str[++i] = 'I';
- if (style & styleUnder)
- str[++i] = 'U';
- if (style & styleOutline)
- str[++i] = 'O';
- if (style & styleShadow)
- str[++i] = 'S';
- if (style & styleSuper)
- str[++i] = 'H';
- if (style & styleSub)
- str[++i] = 'L';
- str[0] = i;
- }
- }
-
-
- /*
- * Convert document format to map spec. The format is put in the
- * input side of the map spec. The format is assumed to be legal.
- */
-
- void
- FormatToMSpec (Format *fmt, MapSpec *mSpec)
- {
- ConvSpec *cSpec;
-
- ClearMSpec (mSpec);
- cSpec = &mSpec->inFmt;
- cSpec->size = fmt->fmtSize;
- cSpec->style = fmt->fmtStyle;
- cSpec->font = fmt->fmtFont;
- }
-